<template>
    <div class="photoinfo-container">
        <h3 class="title">{{ photoInfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间: {{ photoInfo.addTime | dateFormat }}</span>
            <span>点击: {{ photoInfo.click }}次</span>
        </p>

        <hr>

        <vue-preview :slides="photoImgs" @close="handleClose"></vue-preview>

        <div class="content" v-html="photoInfo.content">
        </div>

        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
//导入评论子组件
import comment from '@/components/Comment'

export default {
    data() {
        return {
            id: this.$route.params.id,
            photoInfo: {},
            photoImgs: []
        }
    },
    methods: {
        getPhotoInfo() {
            this.$http.get('http://192.168.31.40:8080/vue/getPhotoInfo/' + this.id).then(result => {
                if (result.body.status === 0) {
                    this.photoInfo = result.body.message;
                    //组建缩略图需要的数据
                    this.photoInfo.photoImgs.forEach(photoImg => {
                        this.photoImgs.push({src: photoImg.img,msrc: photoImg.img,w: 600,h: 400});
                    });
                } 
            });
        },
        handleClose () {
        console.log('close event')
      }
    },
    created() {
        this.getPhotoInfo();
    },
    components: {
        //用来注册子组件
        'comment-box': comment
    }
}
</script>

<style scoped>
    .photoinfo-container {
        padding: 0 4px;
        
    }

    .photoinfo-container .title {
        font-size: 16px;
        text-align: center;
        margin: 15px 0;
        color: blue;
    }

    .photoinfo-container .subtitle {
        font-size: 13px;
        display: flex;
        justify-content: space-between;
    }
</style>